<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>
        X-admin v1.0
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/css/x-admin.css" media="all">
</head>
<body>

<div class="x-body">
    <form class="layui-form" method="post" action="/system/role/doEdit">

        <div class="layui-form-item">
            <label for="roleName" class="layui-form-label">
                <span class="x-red">*</span>角色名
            </label>
            <div class="layui-input-inline">
                <input type="hidden" id="id" value="${sysRole.id}" name="id">
                <input type="text" id="roleName" name="roleName" value="${(sysRole.roleName)!}" required=""
                       lay-verify="required"
                       autocomplete="off" placeholder="请输入角色名" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="roleDesc" class="layui-form-label">描述</label>
            <textarea class="layui-textarea" id="roleDesc" name="roleDesc" rows="3" placeholder="请输入描述，最多300个字符 ...">${(sysRole.roleDesc)!}</textarea>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否启用</label>
            <div class="layui-input-block">
                <input type="radio" name="userState" value="1" title="启用"
                <#if sysRole.roleState = 1> checked</#if>
                >
                <input type="radio" name="userState" value="-1" title="禁用"
                <#if sysRole.roleState = -1> checked</#if>
                >
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="save">保存</button>
            </div>
        </div>
    </form>
</div>
<script src="/lib/layui/layui.js" charset="utf-8">
</script>
<script src="/js/x-layui.js" charset="utf-8">
</script>
<script>
    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form()
                ,layer = layui.layer;

        //监听提交
        form.on('submit(save)', function(data){
            $.ajax({
                url:"/system/role/doEdit",
                dataType:"json",
                data:{
                    id:$("#id").val(),
                    roleName:$("#userName").val(),
                    userDesc:$("#userDesc").val(),
                    userState:$('input:radio:checked').val(),
                },
                type:"POST",
                async:false,
                success:function (res) {
                    if(res.meta.success){
                        layer.alert("操作成功", {icon: 6},function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.location.reload();
                            parent.layer.close(index);
                        });
                    }else{
                        layer.msg("操作失败", {icon: 1});
                    }
                },
                error:function (XMLHttpRequest) {
                    layer.msg("系统错误", {icon: 1});
                }
            })
            return false;
        });


    });
</script>
</body>
</html>
